export const serverUrl = 'http://192.168.18.24:3006';

export const logoUrl =
  'https://img1.baidu.com/it/u=3272371576,3399466349&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500';

/**
 *
 * @param token 存token呢
 * @returns
 */
export const setToken = (token: string) => sessionStorage.setItem('token', token);

/**
 *
 * @param token 取token呢
 * @returns
 */
export const getToken = () => sessionStorage.getItem('token');

/**
 *
 * @param token 删token呢
 * @returns
 */
export const removeToken = () => sessionStorage.removeItem('token');

/**
 *
 * @param n 生成长度为n的验证码
 * @returns
 */
export const randomCaptcha = (n: number) => {
  let result = [];
  for (let i = 0; i < n; i++) {
    if (Math.random() >= 0.75) {
      //生成大写字母
      let ranNum = Math.ceil(Math.random() * 25);
      result.push(String.fromCharCode(65 + ranNum));
    } else if (Math.random() >= 0.5) {
      //生成小写字母
      let ranNum = Math.ceil(Math.random() * 25);
      result.push(String.fromCharCode(97 + ranNum));
    } else {
      //生成数字
      let ranNum = Math.ceil(Math.random() * 9);

      result.push(String.fromCharCode(48 + ranNum));
    }
  }
  return result.join('');
};

//生成验证码图片
// export const getCaptcha = (n: number) => {
//   const captcha = randomCaptcha(n);
//   return [request('/common/captcha', { params: { captcha } }), captcha];
// };
